import logging

from rest_framework import serializers

from courses.serializers import CourseSerializer
from orders.models import OrderDetail, Order


logger = logging.getLogger("django")

class OrderDetailSerializer(serializers.ModelSerializer):
    logger.info("OrderDetailSerializer")
    course= CourseSerializer()

    class Meta:
        model = OrderDetail
        fields = ['price','expire_days',
                  'expire_text','expire_time','course']



class   OrderDetailInfoSerializer (serializers.ModelSerializer):
    logger.info("OrderDetailInfoSerializer")
    order_details = OrderDetailSerializer(many=True, read_only=True)
    order_status_text = serializers.CharField(source='get_order_status_display',read_only=True)
    pay_method_text = serializers.CharField(source='get_pay_method_display',read_only=True)


    class Meta:
        model = Order
        fields =['id','order_number','total_price',
                 "real_price","order_status","order_status_text","pay_method",
                 "pay_method_text","order_desc","order_time",
                 "pay_time","trade_no","order_details"]
